package com.caregiver.watch.business.user.controller;

import com.caregiver.watch.business.user.model.dto.AddContactParam;
import com.caregiver.watch.business.user.model.dto.AddUserAlarmClockConfigParam;
import com.caregiver.watch.business.user.model.dto.AddUserReminderParam;
import com.caregiver.watch.business.user.model.dto.AvatarParam;
import com.caregiver.watch.business.user.model.dto.BindAddressParam;
import com.caregiver.watch.business.user.model.dto.ChangeEmailParam;
import com.caregiver.watch.business.user.model.dto.ChangePhoneParam;
import com.caregiver.watch.business.user.model.dto.EditAddressParam;
import com.caregiver.watch.business.user.model.dto.EditContactParam;
import com.caregiver.watch.business.user.model.dto.RealNameParam;
import com.caregiver.watch.business.user.model.dto.RegisterParam;
import com.caregiver.watch.business.user.model.dto.UpdateEnabledStatusParam;
import com.caregiver.watch.business.user.model.dto.UpdateUserAlarmClockConfigEnabledStatusParam;
import com.caregiver.watch.business.user.model.dto.UpdateUserAlarmClockConfigParam;
import com.caregiver.watch.business.user.model.dto.UpdateUserHealthGoalParam;
import com.caregiver.watch.business.user.model.dto.UpdateUserReminderParam;
import com.caregiver.watch.business.user.model.dto.UserHealthGoalParam;
import com.caregiver.watch.business.user.model.vo.AccessTokenVo;
import com.caregiver.watch.business.user.model.vo.ContactVo;
import com.caregiver.watch.business.user.model.vo.DeliveryAddressVo;
import com.caregiver.watch.business.user.model.vo.UserAlarmClockConfigVo;
import com.caregiver.watch.business.user.model.vo.UserHealthGoalVo;
import com.caregiver.watch.business.user.model.vo.UserInfoVo;
import com.caregiver.watch.business.user.model.vo.UserReminderVo;
import com.caregiver.watch.business.user.service.UserAddressService;
import com.caregiver.watch.business.user.service.UserAlarmClockService;
import com.caregiver.watch.business.user.service.UserContactService;
import com.caregiver.watch.business.user.service.UserReminderService;
import com.caregiver.watch.business.user.service.UserService;
import com.caregiver.watch.common.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 用户登录控制器
 * @Author 疆戟
 * @Date 2025/8/13 23:53
 * @Version 1.0
 */
@Tag(name  = "UserLoginController", description = "用户控制器")
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserAddressService userAddressService;
    @Autowired
    private UserContactService userContactService;
    @Autowired
    private UserReminderService userReminderService;
    @Autowired
    private UserAlarmClockService userAlarmClockService;


    @Operation(summary = "验证手机号是否已经存在", description = "检查手机号是否已经被注册")
    @GetMapping("checkPhoneExists")
    public R<Boolean> checkPhoneExists(@RequestParam("phone") String phone) {
        return R.ok(userService.checkPhoneExists(phone));
    }

    @Operation(summary = "用户注册", description = "用户注册接口")
    @PostMapping("register")
    public R<AccessTokenVo> register(@RequestBody RegisterParam param) {
        return R.ok(userService.register(param));
    }


    @Operation(summary = "获取用户信息", description = "获取用户信息")
    @GetMapping("getUserInfo")
    public R<UserInfoVo> getUserInfo() {
        return R.ok(userService.getUserInfo());
    }

    @Operation(summary = "设置头像", description = "设置头像")
    @PostMapping("setAvatar")
    public R<Boolean> setAvatar(@RequestBody AvatarParam avatar) {
        return R.ok(userService.setAvatar(avatar));
    }

    @Operation(summary = "实名认证", description = "实名认证")
    @PostMapping("realName")
    public R<Boolean> realName(@RequestBody RealNameParam param) {
        return R.ok(userService.realName(param));
    }


    @Operation(summary = "更换手机号", description = "更换手机号")
    @PostMapping("changePhone")
    public R<Boolean> changePhone(@RequestBody ChangePhoneParam param) {
        return R.ok(userService.changePhone(param));
    }


    @Operation(summary = "查询收货地址", description = "查询收货地址")
    @GetMapping("queryAddress")
    public R<List<DeliveryAddressVo>> queryAddress() {
        return R.ok(userAddressService.queryAddress());
    }

    @Operation(summary = "绑定收货地址", description = "绑定收货地址")
    @PostMapping("bindAddress")
    public R<Boolean> bindAddress(@RequestBody BindAddressParam param) {
        return R.ok(userAddressService.bindAddress(param));
    }

    @Operation(summary = "修改收货地址", description = "修改收货地址")
    @PostMapping("editAddress")
    public R<Boolean> editAddress(@RequestBody EditAddressParam param) {
        return R.ok(userAddressService.editAddress(param));
    }

    @Operation(summary = "删除收货地址", description = "删除收货地址")
    @DeleteMapping("deleteAddress")
    public R<Boolean> deleteAddress(@RequestParam("addressId") Long addressId) {
        return R.ok(userAddressService.deleteAddress(addressId));
    }

    @Operation(summary = "更换邮箱", description = "更换邮箱")
    @PostMapping("changeEmail")
    public R<Boolean> changeEmail(@RequestBody ChangeEmailParam param) {
        return R.ok(userService.changeEmail(param));
    }


    @Operation(summary = "获取联系人列表", description = "获取联系人列表")
    @GetMapping("queryContacts")
    public R<List<ContactVo>> queryContacts() {
        return R.ok(userContactService.queryContacts());
    }

    @Operation(summary = "新增联系人", description = "新增联系人")
    @PostMapping("addContact")
    public R<Boolean> addContact(@RequestBody AddContactParam param) {
        return R.ok(userContactService.addContact(param));
    }

    @Operation(summary = "修改联系人", description = "修改联系人")
    @PostMapping("editContact")
    public R<Boolean> editContact(@RequestBody EditContactParam param) {
        return R.ok(userContactService.editContact(param));
    }

    @Operation(summary = "删除联系人", description = "删除联系人")
    @PostMapping("deleteContact")
    public R<Boolean> deleteContact(@RequestParam("contactId") Long contactId) {
        return R.ok(userContactService.deleteContact(contactId));
    }

    @Operation(summary = "查询用户提醒列表", description = "查询用户提醒列表")
    @GetMapping("queryUserReminderList")
    public R<List<UserReminderVo>> queryUserReminderList() {
        return R.ok(userReminderService.queryUserReminderList());
    }

    @Operation(summary = "新增亲情提醒", description = "新增亲情提醒")
    @PostMapping("addUserReminder")
    public R<Boolean> addUserReminder(@RequestBody AddUserReminderParam param) {
        return R.ok(userReminderService.addUserReminder(param));
    }

    @Operation(summary = "删除亲情提醒", description = "删除亲情提醒")
    @PostMapping("deleteUserReminder")
    public R<Boolean> deleteUserReminder(@RequestParam("id") Long id) {
        return R.ok(userReminderService.deleteUserReminder(id));
    }

    @Operation(summary = "更新亲情提醒", description = "更新亲情提醒")
    @PostMapping("updateUserReminder")
    public R<Boolean> updateUserReminder(@RequestBody UpdateUserReminderParam param) {
        return R.ok(userReminderService.updateUserReminder(param));
    }

    @Operation(summary = "更新提醒的启用状态", description = "更新提醒的启用状态")
    @PostMapping("updateEnabledStatus")
    public R<Boolean> updateEnabledStatus(@RequestBody UpdateEnabledStatusParam param) {
        return R.ok(userReminderService.updateEnabledStatus(param));
    }

    @Operation(summary = "查询用户提醒", description = "查询用户提醒")
    @GetMapping("queryUserReminder")
    public R<UserReminderVo> queryUserReminder(@RequestParam("id") Long id) {
        return R.ok(userReminderService.queryUserReminder(id));
    }

    @Operation(summary = "查询用户闹钟列表", description = "查询用户闹钟列表")
    @GetMapping("queryUserAlarmClockConfigs")
    public R<List<UserAlarmClockConfigVo>> queryUserAlarmClockConfigs() {
        return R.ok(userAlarmClockService.queryUserAlarmClockConfigs());
    }

    @Operation(summary = "新增用户闹钟", description = "新增用户闹钟")
    @PostMapping("addUserAlarmClockConfig")
    public R<Boolean> addUserAlarmClockConfig(@RequestBody AddUserAlarmClockConfigParam param) {
        return R.ok(userAlarmClockService.addUserAlarmClockConfig(param));
    }

    @Operation(summary = "删除用户闹钟", description = "删除用户闹钟")
    @PostMapping("deleteUserAlarmClockConfig")
    public R<Boolean> deleteUserAlarmClockConfig(@RequestParam("configId") Long configId) {
        return R.ok(userAlarmClockService.deleteUserAlarmClockConfig(configId));
    }

    @Operation(summary = "更新用户闹钟", description = "更新用户闹钟")
    @PostMapping("updateUserAlarmClockConfig")
    public R<Boolean> updateUserAlarmClockConfig(@RequestBody UpdateUserAlarmClockConfigParam param) {
        return R.ok(userAlarmClockService.updateUserAlarmClockConfig(param));
    }

    @Operation(summary = "更新用户闹钟的启用状态", description = "更新用户闹钟的启用状态")
    @PostMapping("updateUserAlarmClockConfigEnabledStatus")
    public R<Boolean> updateUserAlarmClockConfigEnabledStatus(@RequestBody UpdateUserAlarmClockConfigEnabledStatusParam param) {
        return R.ok(userAlarmClockService.updateUserAlarmClockConfigEnabledStatus(param.getConfigId(), param.getIsEnabled()));
    }

    @Operation(summary = "设置用户健康目标", description = "设置用户健康目标")
    @PostMapping("setUserHealthGoal")
    public R<Boolean> setUserHealthGoal(@RequestBody UserHealthGoalParam param) {
        return R.ok(userService.setUserHealthGoal(param));
    }

    @Operation(summary = "查询用户健康目标", description = "查询用户健康目标")
    @GetMapping("queryUserHealthGoal")
    public R<UserHealthGoalVo> queryUserHealthGoal() {
        return R.ok(userService.queryUserHealthGoal());
    }
}
